import tkinter as tk

class Scrollbar_Example:
    def __init__(self):
        self.window = tk.Tk()
        self.scrollbar = tk.Scrollbar(self.window)
        self.scrollbar.pack(side="right", fill="y")
        self.listbox = tk.Listbox(self.window, yscrollcommand=self.scrollbar.set)

        x=print('num')

        for i in range(5):

            self.listbox.insert("end", str(x))

        self.listbox.pack(side="top", fill="both")
        self.scrollbar.config(command=self.listbox.yview)
        self.window.mainloop()

if __name__ == '__main__':
    app = Scrollbar_Example()